package com.vng.zini.gifapp.components;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.vng.zini.gifapp.activity.CameraActivity;
import com.vng.zini.gifapp.config.AppParameters;
import com.vng.zini.giffapp.R;

public class SettingDialog {
	Dialog dialog;
	private TextView setting_tv1;
	private Button numFrame1,numFrame2,frameSize1,frameSize2;
	private int progressSeekBar;
	private Context context;
	private SeekBar seekbar;
	public SettingDialog(Context _context){
		this.context = _context;
		
		dialog = new Dialog(context);
		dialog.setContentView(R.layout.layout_settings);
		dialog.setTitle("Cài đặt");
		progressSeekBar = 25;
		setListenerOnSettings();
		
		
	}
	public void show(){
		dialog.show();
	}
	
	private void setListenerOnSettings(){
		setting_tv1 = (TextView) dialog.findViewById(R.id.setting_tv_1);
		numFrame1 = (Button) dialog.findViewById(R.id.setting_btn1);
		numFrame2 = (Button) dialog.findViewById(R.id.setting_btn2);
		frameSize1 = (Button) dialog.findViewById(R.id.setting_btn3);
		frameSize2 = (Button) dialog.findViewById(R.id.setting_btn4);
		
		float value = 0.9f*progressSeekBar/100f + 0.1f;
    	setting_tv1.setText("Tốc độ tự động: "+String.format("%.02f", value)+"sec mỗi hình");
    	
    	if(AppParameters.numberFrames == 20){
    		numFrame1.setTextColor(context.getResources().getColor(R.color.white_color));
    		numFrame2.setTextColor(context.getResources().getColor(R.color.black_color));
    	}else{
    		numFrame2.setTextColor(context.getResources().getColor(R.color.white_color));
    		numFrame1.setTextColor(context.getResources().getColor(R.color.black_color));
    	}
    	
    	if(AppParameters.frameSmall == true){
    		frameSize1.setTextColor(context.getResources().getColor(R.color.white_color));
    		frameSize2.setTextColor(context.getResources().getColor(R.color.black_color));
    	}
    	else{
    		frameSize2.setTextColor(context.getResources().getColor(R.color.white_color));
    		frameSize1.setTextColor(context.getResources().getColor(R.color.black_color));
    	}
    	
		seekbar = (SeekBar) dialog.findViewById(R.id.setting_seekbar);
		seekbar.setProgress(progressSeekBar);
		seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
 
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
            	progressSeekBar = progress;
            	float value = 0.9f*progress/100f + 0.1f;
            	setting_tv1.setText("Tốc độ tự động: "+String.format("%.02f", value)+"sec mỗi hình");
            	AppParameters.time_sleep = (int)(value*1000);
            }
 
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
 
            public void onStopTrackingTouch(SeekBar seekBar) {
                
            }
        });
		
		numFrame1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AppParameters.numberFrames = 20;
				//tv_time.setText(String.valueOf(numberFrames));
				AppParameters.camera_time = AppParameters.numberFrames;
				numFrame1.setTextColor(context.getResources().getColor(R.color.white_color));
	    		numFrame2.setTextColor(context.getResources().getColor(R.color.black_color));
			}
		});
		
		numFrame2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AppParameters.numberFrames = 30;
				//tv_time.setText(String.valueOf(numberFrames));
				AppParameters.camera_time = AppParameters.numberFrames;
				numFrame2.setTextColor(context.getResources().getColor(R.color.white_color));
	    		numFrame1.setTextColor(context.getResources().getColor(R.color.black_color));
			}
		});
		
		frameSize1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AppParameters.frameSmall = true;
				frameSize1.setTextColor(context.getResources().getColor(R.color.white_color));
				frameSize2.setTextColor(context.getResources().getColor(R.color.black_color));
			}
		});
		
		frameSize2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AppParameters.frameSmall = false;
				frameSize2.setTextColor(context.getResources().getColor(R.color.white_color));
				frameSize1.setTextColor(context.getResources().getColor(R.color.black_color));
			}
		});
		
	}
}
